package com.dragon.blog.cms.controller;

import com.dragon.blog.cms.entity.LogEntity;
import com.dragon.blog.cms.service.LogService;
import com.dragon.blog.utils.PageUtils;
import com.dragon.blog.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 系统日志
 *
 * @author NAIZUI
 * @email 18140109033@163.com
 * @date 2021-09-23 18:41:16
 */
@Api(tags = "系统日志", description = "LogController", value = "系统日志接口")
@RefreshScope
@RestController
@RequestMapping("cms/log")
public class LogController {
    @Autowired
    private LogService logService;

    @Value("${api.user.name}")
    private String name;
    @Value("${api.user.age}")
    private Integer age;

    @RequestMapping("/test")
    public R test(){
        return R.ok().put("name", name).put("age", age);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("cms:log:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = logService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("cms:log:info")
    public R info(@PathVariable("id") Long id) {
        LogEntity log = logService.getById(id);

        return R.ok().put("log", log);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("cms:log:save")
    public R save(@RequestBody LogEntity log) {
        logService.save(log);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("cms:log:update")
    public R update(@RequestBody LogEntity log) {
        logService.updateById(log);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @ApiOperation(nickname = "132", value = "删除日志", notes = "逻辑删除日志")
    @ApiOperation(value = "删除日志信息", notes = "逻辑删除日志", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    //@RequiresPermissions("cms:log:delete")
    public R delete(@RequestBody Long[] ids) {
        logService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
